package chp12;

public class Tool4 {

    public static void main(String[] args) {
        int[] nums = {34,63,2,56,22};
        AvgAndAbove avgAndAbove = getAvgAndAbove(nums);
        System.out.println("平均值:" + avgAndAbove.avg);
        System.out.println("平均值以上的个数是:"+avgAndAbove.aboveCount);
        //保留精度的平均值 35.4

    }

    //需要找到数组的平均值(保留精度)和数组里面超过平均值的元素的个数
    public static AvgAndAbove getAvgAndAbove(int[] nums){
        double sum =0;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
        }
        double avg = sum/nums.length;
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if(nums[i] > avg){
                count++;
            }
        }
        //把零散的数据打包为对象
        AvgAndAbove avgAndAbove = new AvgAndAbove();
        avgAndAbove.avg = avg;
        avgAndAbove.aboveCount = count;
        return avgAndAbove;
        //int[] double[]
    }
}
